﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.wMall.Buyer
{
    public partial class wfCheckDemand : msBsc.Cls.BPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public override void DoAction()
        {
            if (this.strAction == "InitInfo")
            {
                GetInitInfo();
            }
            else if (this.strAction == "CheckService")
            {
                CheckedServiceInfo();
            }
        }

        /// <summary>
        /// 获取展示信息
        /// </summary>
        private void GetInitInfo()
        {
            string orderRouteId = this.GetParamHtValue("serviceId");

            if (string.IsNullOrWhiteSpace(orderRouteId))
            {
                this.Alert("预定信息有误");
                return;
            }

            using (msBsc.AppLogic.DataAlc.CBizDjkOrderService objCBizDjkOrderService = new AppLogic.DataAlc.CBizDjkOrderService())
            {
                System.Data.DataSet ds = objCBizDjkOrderService.GetOrderServiceById(orderRouteId);

                if (ds == null
                    || ds.Tables[0].Rows.Count <= 0)
                {
                    this.Alert("预定信息不存在");
                    return;
                }

                if (ds.Tables[0].Rows[0]["ORDER_ROUTE_STATUS"].ToString() != "1")
                {
                    this.Alert("该条信息当前状态不能进行预案确定");
                    return;
                }

                string retJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "ORDER_SERVICE_ID,ORDER_ROUTE_ID,ORDER_ROUTE_NME,ORDER_ROUTE_TYPE,ORDER_ROUTE_DAYS,ORDER_VEHICLE_ID,ORDER_VEHICLE_NME,ORDER_VEHICLE_SEATS,ORDER_VEHICLE_TYPE,VEHICLE_TYPE_NME,ORDER_VEHICLE_BRAND,VEHICLE_BRAND_NME,ORDER_DJACK_ID,ORDER_DJACK_NME,BEGIN_SERVICE_DT,BEGIN_SERVICE_ADDR,TOTAL_CHARGE,BUYER_NME,BUYER_PHONE,COUNTRY_NME,CITY_NME,DESTINATION_NME,ORDER_ROUTE_STATUS,DETAIL_BELONG_DAY", 1, 1000, "");

                this.ExecJScript(@"var _html = $('#svc_list_temp_order').html();
                            laytpl(_html).render(" + retJson + @", function (render) {
                                $('#requestData').html(render);
                            });");
            }
        }

        /// <summary>
        /// 确定预定方案信息
        /// </summary>
        private void CheckedServiceInfo()
        {
            string serviceId = this.GetParamHtValue("serviceId");

            if (string.IsNullOrWhiteSpace(serviceId))
            {
                this.ExecJScript(@"$("".result-msg"").text(""预定方案信息有误"").css(""color"", ""#f00"")");
                return;
            }

            using (msBsc.AppLogic.DataAlc.CBizDjkOrderService objCBizDjkOrderService = new AppLogic.DataAlc.CBizDjkOrderService())
            {
                System.Data.DataSet ds = objCBizDjkOrderService.SelectById(serviceId);

                if (ds == null
                    || ds.Tables[0].Rows.Count <= 0)
                {
                    this.ExecJScript(@"$("".result-msg"").text(""预定信息不存在"").css(""color"", ""#f00"")");
                    return;
                }

                if (ds.Tables[0].Rows[0]["ORDER_ROUTE_STATUS"].ToString() != "1")
                {
                    this.ExecJScript(@"$("".result-msg"").text(""该条信息当前状态不能进行预案确定"").css(""color"", ""#f00"")");
                    return;
                }

                ds.Tables[0].Rows[0]["ORDER_ROUTE_STATUS"] = "2";

                objCBizDjkOrderService.Update(ds);

                this.ExecJScript(@"$("".result-msg"").text(""您提交的预定方案，已经处理生成服务线路，请您进行确认并生成订单。"")");
            }
        }
    }
}